package com.liry.security.config;

import com.liry.security.domain.entity.SysUser;
import com.liry.security.service.SysUserService;
import lombok.AllArgsConstructor;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;

/**
 * @author ALI
 * @since 2023/5/29
 */
@Component
@AllArgsConstructor
public class CustomUserServiceImpl implements UserDetailsService {
    private SysUserService sysUserService;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        SysUser sysUser = sysUserService.getByUsername(username);
        if (sysUser == null) {
            return null;
        }
        return new CustomUser(sysUser);
    }
}
